{% extends "layout.html" %}

{%block nav%}
<ul class="nav nav-sidebar">
    <li id="require_li" class="active"><a href="/">需求</a></li>
    <li id="server_li"><a href="/server/list">服务器配置</a></li>
    <li id="project_li"><a href="/project/list">项目信息</a></li>
</ul>
{% endblock %}

{% block body %}

<a href="/requirement/add">新增需求</a>

<table class="table table-striped">
    <thead>
    <tr>
        <th>需求名称</th>
        <th>项目名称</th>
        <th>服务器地址</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody>
    {% for requirement in all_requirement %}
    <td>{{requirement.name }}</td>
    <td>{{requirement.project_name}}</td>
    <td>
        {% for server_ip in requirement.server_ip_list%}
        {%if loop.index<4%}
        <span class="label label-info">{{server_ip}}</span>
        {% endif %}
        {% endfor%}
        {% if requirement.server_ip_list |length >3%}
        <a class="btn btn-primary btn_more" role="button" data-toggle="collapse" href="#" aria-expanded="false"
           aria-controls="collapseExample" tag="{{requirement.id}}" >
            更多
        </a>

        <div class="collapse" tag="{{requirement.id}}">
            {% for server_ip in requirement.server_ip_list%}
            {%if loop.index>=4%}
            <span class="label label-info">{{server_ip}}</span>
            {% endif %}
            {% endfor%}
        </div>

        {% endif %}
    </td>
    <td>
        <div class="dropdown">
            <button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown"
                    aria-haspopup="true" aria-expanded="true">
                操作
            </button>
            <ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
                <li>
                    <a href="#" class="package_btn" tag="{{requirement.id}}">打包</a>
                </li>
                <li>
                    <a href="#" class="deploy_btn" tag="{{requirement.id}}">发布</a>
                </li>
                <li>
                    <a href="#" class="restart_btn" tag="{{requirement.id}}">重启</a>
                </li>
                <li>
                    <a href="#" class="init_btn" tag="{{requirement.id}}">初始化项目</a>
                </li>
            </ul>
        </div>


    </td>


    </tr>
    {% endfor %}
    </tbody>
</table>

<script type="text/javascript">
    $(function () {
        $.blockUI.defaults.message = '<i class="fa fa-cog fa-spin"></i>'
        $(document).ajaxStart($.blockUI).ajaxStop($.unblockUI);
        $(".package_btn").click(function () {
            $.get('/build/' + $(this).attr("tag"), function (data) {
                alert('打包成功');
            });
        });

        $(".deploy_btn").click(function () {
            $.get('/deploy/' + $(this).attr("tag"), function (data) {
                alert('发布成功');
            });
        });

        $(".restart_btn").click(function () {
            $.get('/restart/' + $(this).attr("tag"), function (data) {
                alert('重启成功');
            });
        });

        $(".init_btn").click(function () {
            $.get('/init/' + $(this).attr("tag"), function (data) {
                alert('初始化成功');
            });
        });

         $(".btn_more").click(function () {
          var id= $(this).attr('tag');
             $('.collapse[tag='+id+']').collapse();
        });

    });





</script>


{% endblock %}